import Vue from 'vue'
import Router from 'vue-router'
import tabBar from './tabBar.js'
//下面四句代码是为了处理router.beforeEach的异常报错(https://blog.csdn.net/haidong55/article/details/100939076)
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch((err) => err)
}

Vue.use(Router)

/**
 * meta属性
 *     title:标题
 *     auth:是否需要登录
 *     keepAliv:是否缓存
 *      showTab:是否展示底部tab导航
 */

const router = new Router({
  mode: 'hash',
  // base: '/vapps/pages-test/',
  routes: [
    {
      path: '/',
      redirect: '/home',
    },
    ...tabBar, //tabBar导航

    {
      path: '/luck-draw',
      component: () => import('@/pages/luck-draw/index.vue'),
      meta: {
        title: '九宫格抽奖',
        auth: false,
      },
    },
    {
      path: '/gray-chart',
      component: () => import('@/pages/gray-chart/index.vue'),
      meta: {
        title: '黑白界面',
        auth: false,
      },
    },
    {
      path: '/light-move-btn',
      component: () => import('@/pages/light-move-btn/index.vue'),
      meta: {
        title: '按钮光影',
        auth: false,
      },
    },
    {
      path: '/to-top',
      component: () => import('@/pages/to-top/index.vue'),
      meta: {
        title: '回到顶部',
        auth: false,
      },
    },
    {
      path: '/box-scroll',
      component: () => import('@/pages/box-scroll/index.vue'),
      meta: {
        title: '独立盒子滚动',
        auth: false,
      },
    },
    {
      path: '/drag-box',
      component: () => import('@/pages/drag-box/index.vue'),
      meta: {
        title: '拖拽盒子',
        auth: false,
      },
    },
    {
      path: '/3D-font',
      component: () => import('@/pages/3D-font/index.vue'),
      meta: {
        title: '3D字体',
        auth: false,
      },
    },
    {
      path: '/jigsaw-puzzle',
      component: () => import('@/pages/jigsaw-puzzle/index.vue'),
      meta: {
        title: '拼图',
        auth: false,
      },
    },
    {
      path: '/scroll-disappear',
      component: () => import('@/pages/scroll-disappear/index.vue'),
      meta: {
        title: '滚动消失',
        auth: false,
      },
    },
    {
      path: '/bullet-chat',
      component: () => import('@/pages/bullet-chat/index.vue'),
      meta: {
        title: '滚动弹幕',
        auth: false,
      },
    },
    {
      path: '/AI-body',
      component: () => import('@/pages/AI-body/index.vue'),
      meta: {
        title: 'AI-body',
        auth: false,
      },
    },
    {
      path: '/china-map',
      component: () => import('@/pages/china-map/index.vue'),
      meta: {
        title: '中国地图',
        auth: false,
      },
    },
    {
      path: '/QR-code',
      component: () => import('@/pages/QR-code/index.vue'),
      meta: {
        title: '二维码生成',
        auth: false,
      },
    },
    {
      path: '/location',
      component: () => import('@/pages/location/index.vue'),
      meta: {
        title: '定位',
        auth: false,
      },
    },
    {
      path: '/face-acquisition',
      meta: {
        title: '人脸采集',
        auth: false,
      },
      component: () => import('@/pages/face-acquisition/index.vue'),
    },
    {
      path: '/scan',
      meta: {
        title: '人脸采集',
        auth: false,
      },
      component: () => import('@/pages/scan/index.vue'),
    },
    {
      path: '/voice-announcements',
      meta: {
        title: '语音播报',
        auth: false,
      },
      component: () => import('@/pages/voice-announcements/index.vue'),
    },
  ],
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})
export default router
